package com.fwtai.controller.web;

import com.fwtai.bean.PageFormData;
import com.fwtai.service.web.CouponService;
import com.fwtai.tool.ToolClient;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;

/**
 * 商品优惠券控制层|路由层
 * @作者 田应平
 * @版本 v1.0
 * @QQ号码 444141300
 * @Email service@fwtai.com
 * @创建日期 2024-01-04 18:08:42
 * @官网 <url>http://www.fwtai.com</url>
*/
@RestController
@RequestMapping("/coupon")
public class CouponController{

  private final CouponService couponService;

  public CouponController(final CouponService couponService){
    this.couponService = couponService;
  }

  /**优惠券添加*/
  @PreAuthorize("hasAuthority('coupon_btn_add')")
  @PostMapping("/add")
  public void add(final HttpServletRequest request,final HttpServletResponse response){
    ToolClient.responseJson(couponService.add(request),response);
  }

  /**优惠券编辑(行内编辑)*/
  @PreAuthorize("hasAuthority('coupon_row_edit')")
  @PostMapping("/edit")
  public void edit(final HttpServletRequest request,final HttpServletResponse response){
    ToolClient.responseJson(couponService.edit(request),response);
  }

  /**删除商品优惠券发放规则*/
  @PreAuthorize("hasAuthority('coupon_row_del')")
  @PostMapping("/delCoupon")
  public void delCoupon(final String goodsId,final String areaId,final HttpServletResponse response){
    ToolClient.responseJson(couponService.delCoupon(goodsId,areaId),response);
  }

  /**根据id查询对应的数据*/
  @PreAuthorize("hasAuthority('coupon_row_queryById')")
  @GetMapping("/queryById")
  public void queryById(final Long id,final HttpServletResponse response){
    ToolClient.responseJson(couponService.queryById(id),response);
  }

  /**获取区域数据构建树形列表*/
  @PreAuthorize("hasAuthority('coupon_btn_listData')")
  @GetMapping("/listData")
  public void listData(final HttpServletRequest request,final HttpServletResponse response){
    ToolClient.responseJson(couponService.listData(new PageFormData(request)),response);
  }

  /**获取数据,用于构建树形*/
  @PreAuthorize("hasAuthority('coupon_btn_tree')")
  @GetMapping("/getCouponTree")
  public void getCouponTree(final String kid,final String goodsId,final HttpServletResponse response){
    ToolClient.responseJson(couponService.getCouponTree(kid,goodsId),response);
  }
}